package JUC.创建线程.资源共享;

public class ShareSourceByRunnable {
    public static void main(String[] args) {
        Stationn stationn = new Stationn();
        new Thread(stationn, "窗口1").start();
        new Thread(stationn, "窗口2").start();
    }
}
class Stationn implements Runnable {
    int ticket = 10;

    @Override
    public void run() {
        while (ticket > 0) {
            synchronized (this) { // 自：共享 一个 runnbale对象 线程内存区域 当然可以用this
                System.out.println(Thread.currentThread().getName() + "卖出第 " + (10 - ticket) + "张票");
                ticket--;
            }
        }
    }
}
